package com.qys.training.server.controller;

import com.qys.training.base.dto.BaseResult;
import com.qys.training.biz.cache.service.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Winstone
 * @date 2020/8/5 - 2:06 下午
 */
@RestController
public class CacheController {
    @Autowired
    CacheService cacheService;

    @GetMapping("/put")
    public String put(@RequestParam("cache") String name, @RequestParam("key") String key, @RequestParam("value") String value,@RequestParam(name = "ttl",defaultValue = "100") long ttl) {
        return cacheService.put(name, key, value, ttl);
    }

    @GetMapping("/get")
    public String getValue(@RequestParam("cache") String name, @RequestParam("key") String key) {
        return cacheService.getValue(name, key);
    }

    @GetMapping("/delete")
    public BaseResult delete(@RequestParam("cache") String name, @RequestParam("key") String key) {
        cacheService.deleteCache(name, key);
        return BaseResult.success();
    }
}
